package com.lc1993929.tuling;

/**
 * Created by LiuChang on 2017/5/5.
 */

import net.sf.json.JSONObject;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

/**
 * 图灵机器人接口流程控制类
 */
public class TulingController {
    /**
     * 调用图灵机器人接口，并返回所需内容
     */
    public String getTulingRe(String info) {
        //调用图灵机器人接口api，获取结果
        List<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("key", "996a7ca7038c435e9786c2b82be3419c"));
        try {
            params.add(new BasicNameValuePair("info", URLDecoder.decode(info, "utf-8")));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        String tlResult = HttpPostRequest.post(params);

        //解析图灵结果数据，提取所需内容
        JSONObject json = JSONObject.fromObject(tlResult);
        tlResult = json.getString("text");

        return tlResult;
    }

}
